package util

import (
	"strconv"
)

func StrSlice2IntSlice(strSlice []string, isRepeat bool) []int {
	o := make([]int, 0)
	if isRepeat {
		for i := range strSlice {
			o = append(o, S2I(strSlice[i]))
		}
		return o
	}

	oMap := make(map[int]int)
	for i := range strSlice {
		oMap[S2I(strSlice[i])] = 1
	}
	for key := range oMap {
		o = append(o, key)
	}
	return o
}

func IntSlice2StrSlice(intSlice []int) []string {
	o := make([]string, 0)
	for i := range intSlice {
		o = append(o, I2S(intSlice[i]))
	}
	return o
}

func Int64Slice2StrSlice(int64Slice []int64) []string {
	o := make([]string, 0)
	for i := range int64Slice {
		o = append(o, strconv.FormatInt(int64Slice[i], 10))
	}
	return o
}

func Int2SubStr(n int, start, length int) string {
	str := I2S(n)
	lenStr := len(str)
	if start >= lenStr {
		return ""
	}
	if length > len(str[start:]) {
		return str[start:]
	}
	return str[start : start+length]
}
